typedef List<T> RecordParseCallBack<T>(List data);

class RecordData<T> {
  RecordData();

  late List<T> recordModels;
  late List records;
  late num total;
  late num size;
  late num current;
  late List orders;
  late bool optimizeCountSql;
  late bool searchCount;
  late String countId;
  late num maxLimit;
  late num pages;

  // factory RecordData.fromJson(Map<String,dynamic> json) => _$RecordDataFromJson(json);

  factory RecordData.fromJson(Map<String, dynamic> json,
      {RecordParseCallBack<T>? recordParseCallBack}) {
    RecordData<T> recordData = _$RecordDataFromJson(json);
    if (recordData.records.isNotEmpty && recordParseCallBack != null) {
      recordData.recordModels = recordParseCallBack(recordData.records);
    } else {
      recordData.recordModels = [];
    }
    return recordData;
  }

  Map<String, dynamic> toJson() => _$RecordDataToJson(this);
}

// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************

RecordData<T> _$RecordDataFromJson<T>(Map<String, dynamic> json) =>
    RecordData<T>()
      ..records = json['records'] as List<dynamic>
      ..total = json['total'] as num
      ..size = json['size'] as num
      ..current = json['current'] as num
      ..orders = json['orders'] as List<dynamic>
      ..optimizeCountSql = json['optimizeCountSql'] as bool
      ..searchCount = json['searchCount'] as bool
      ..countId = json['countId'] as String
      ..maxLimit = json['maxLimit'] as num
      ..pages = json['pages'] as num;

Map<String, dynamic> _$RecordDataToJson(RecordData instance) =>
    <String, dynamic>{
      'records': instance.records,
      'total': instance.total,
      'size': instance.size,
      'current': instance.current,
      'orders': instance.orders,
      'optimizeCountSql': instance.optimizeCountSql,
      'searchCount': instance.searchCount,
      'countId': instance.countId,
      'maxLimit': instance.maxLimit,
      'pages': instance.pages,
    };
